#include "TcpSession.h"
#include "../Request/RequestManager.h"
#include "../Util/SingletonTemplate.h"

TcpSession::TcpSession(/* args */)
{
}

TcpSession::~TcpSession()
{
}

int TcpSession::Init()
{
    //todo 初始化socket,  tcp连接

    return -1;
}
void TcpSession::Start()
{
    thread_ = std::thread(&TcpSession::ReadThread, this);
}

void TcpSession::ReadThread()
{
    while (running_)
    {
        //todo循环的读 socket解析出相关信息
        // todo 解析出指令的流水号
        uint16_t serial = 0; //指令流水号
        uint16_t cmdtype = 0;//指令类型
        if (0x8001 == cmdtype)//平台通用应答
        { 
            SingletonTemplate<RequestManager>::GetInstance()->SetRequest_GetResponse(serial);
        }
        else if (0x8100)//终端注册应答
        {
            SingletonTemplate<RequestManager>::GetInstance()->SetRequest_GetResponse(serial);
            // todo鉴权码保存到文件
        }
        else
        {

        }
        
        
    }
    
}

//todo socket 发送
int TcpSession::Send(uint8_t* buffer, size_t sz)
{
    return -1;
}